<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .btn{
            padding: 10px 20px;
            border-radius: 10px;
            border: none;
        }
    </style>
</head>
<body>
    <button class="btn">Start long time task</button>

    <script>
        const btn = document.querySelector(".btn");
        function delay(duration=1000){
            const start = Date.now();
            while(Date.now() - start < duration){
                // do nothing
            }
        }
        btn.addEventListener("click", () => {
            delay(500);
            console.log("Task completed");
        })

        const ob = new PerformanceObserver((list) => {
            for(const entry of list.getEntries()){
                console.log("🚀 ~ ob ~ entry:", entry)
                if(entry.duration > 1000){
                    sendReportToServer()
                }
            }
        });
        ob.observe({entryTypes: ["longtask"]});
    </script>
</body>
</html>